package com.example.mardan_demo1.utils;

import java.util.Arrays;

public class ThreadLocalUtil {
//    提供ThreadLocal对象
    private static final ThreadLocal THREAD_LOCAL = new ThreadLocal();

//    根据键值取值
    public static <T> T get(){
        return (T) THREAD_LOCAL.get();
    }
//    存储键值对
    public  static void set(Object value) {
        THREAD_LOCAL.set(value);
    }
//    清除ThreadLocal防止内存泄漏
    public static void remove() {
        THREAD_LOCAL.remove();
    }

    public static int[] parseStringToIntArray(String input) {
        // 去掉字符串中的空格
        String trimmedInput = input.replaceAll("\\\\s", "");

        // 使用逗号分割字符串并转换为整数数组
        return Arrays.stream(trimmedInput.split(","))
                .mapToInt(Integer::parseInt)
                .toArray();
    }
}
